Skip to main content

C# Quick Start

Get OptalCP running in C# in under 5 minutes.

Prerequisites

Installation

OptalCP's NuGet packages are published to the ScheduleOpt GitHub Packages feed, so setup takes three one-time steps before the first dotnet add package.

1. Create a console project

dotnet new console -o hello-optalcp
cd hello-optalcp

2. Create a GitHub personal access token

GitHub authentication required — even for public packages

GitHub Packages requires authentication for every NuGet install, including packages that are publicly readable. There is no anonymous pull. This is a GitHub Packages behavior, not an OptalCP restriction — see the GitHub NuGet registry documentation. You will need to set up a token once, regardless of which edition you install.

Go to github.com/settings/tokens and create a classic personal access token (not a fine-grained token — fine-grained tokens are not supported by the GitHub Packages NuGet endpoint). The only scope needed is read:packages. Copy the token value.

3. Register the ScheduleOpt NuGet source

Run this once per machine. Replace YOUR_GITHUB_USERNAME with your GitHub username and YOUR_GITHUB_TOKEN with the token from step 2.

dotnet nuget add source "https://nuget.pkg.github.com/ScheduleOpt/index.json" \
--name ScheduleOpt \
--username YOUR_GITHUB_USERNAME \
--password YOUR_GITHUB_TOKEN \
--store-password-in-clear-text

On Linux and macOS, --store-password-in-clear-text is required because .NET's encrypted credential store isn't available on those platforms. The token is written to ~/.nuget/NuGet/NuGet.Config.

4. Install the Preview edition

dotnet add package OptalCP.Bin.Preview

This pulls in the OptalCP API package as a transitive dependency and drops the native solver binary into your build output. No further setup is needed — the API locates the binary automatically at runtime.

tip

For academic research or production use, see Editions for other options.

Pinning a version

For reproducible builds, pin a specific version, e.g. dotnet add package OptalCP.Bin.Preview --version 2025.11.0.

Your First Scheduling Model

Replace the contents of Program.cs with:

using OptalCP;

var model = new Model();
var x = model.IntervalVar(length: 10, name: "x");
var y = model.IntervalVar(length: 10, name: "y");
model.Enforce(x.EndBeforeStart(y)); // y starts after x ends
model.Minimize(y.End());
var result = model.Solve();
Console.WriteLine($"Objective: {result.Objective}");

Run it:

dotnet run

You'll see the solver log first, then the output from your program:

────────────────────────────────────────────────────────────────────────────────
                              ScheduleOpt OptalCP
                           Version 2025.12.1 (Linux)
                   CPU: AMD Ryzen 9 5950X (16 physical cores)
────────────────────────────────────────────────────────────────────────────────
Input parse time: 00:00
   nbWorkers = 16                      (auto: 16 physical cores)
   preset = Default                    (auto: < 100,000 variables)
   noOverlapPropagationLevel = 4       (preset: Default)
   cumulPropagationLevel = 3           (preset: Default)
     Workers 0-7: searchType = LNS     (preset: Default)
    Workers 8-13: searchType = FDS     (preset: Default)
   Workers 14-15: searchType = FDSDual (preset: Default)
Input:
   0 integer variables, 2 interval variables, 1 constraints, 9.38kB
   00:00 Presolving..
Presolved:
   0 integer variables, 2 interval variables, 1 constraints, 9.37kB
   00:00 Presolve complete, starting search.
────────────────────────────────────────────────────────────────────────────────
   00:00  Lower bound 20 Worker 8
   00:00 ↓ Solution 20 Worker 8: FDS
   00:00 The current best solution is optimal.
────────────────────────────────────────────────────────────────────────────────
   Objective value: 20 (optimal)
       Lower bound: 20
         Solutions: 1
         LNS steps: 0 (0.00 per second)
          Restarts: 0 (0.00 per second)
          Branches: 156 (8706.41 per second)
             Fails: 10 (558.10 per second)
    Total duration: 00:00.02
            Memory: 146MB
────────────────────────────────────────────────────────────────────────────────
Objective: 20

Next Steps

  • Tutorial — Learn scheduling concepts step-by-step
  • Editions — Compare Preview, Academic, and Full editions
  • C# API — Complete C# API documentation

See also